package com.chixing.ih.module.admin.controller;

import com.chixing.ih.json.ResponseData;
import com.chixing.ih.module.admin.service.IAdminUserService;
import com.chixing.ih.module.system.pojo.User;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("AUC")
@Api(tags = "管理员用户相关Api")
public class AdminUserCon {

    @Autowired
    private IAdminUserService adminUserService;

    @ApiOperation(value = "查看普通用户", notes = "查看所有普通用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("getOrdinaryUser")
    public Map<String, Object> getOrdinaryUser(Integer pageNum, Integer pageSize,String keyword) {
        List<User> ordinaryUser = adminUserService.getOrdinaryUser(pageNum, pageSize,keyword);
        PageInfo<User> info = new PageInfo<>(ordinaryUser);
        return ResponseData.REP_GET_SUCCESS(info);
    }



    @ApiOperation(value = "查看Vip用户", notes = "查看所有Vip用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("getVipUser")
    public Map<String, Object> getVipUser(Integer pageNum, Integer pageSize,String keyword) {
        List<User> vipUser = adminUserService.getVipUser(pageNum, pageSize,keyword);
        PageInfo<User> info = new PageInfo<>(vipUser);
        return ResponseData.REP_GET_SUCCESS(info);
    }


    @ApiOperation(value = "查看黑名单用户", notes = "查看所有黑名单用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("getBlacklistedUser")
    public Map<String, Object> getBlacklistedUser(Integer pageNum, Integer pageSize,String keyword) {
        List<User> blacklistedUser = adminUserService.getBlacklistedUser(pageNum, pageSize,keyword);
        PageInfo<User> info = new PageInfo<>(blacklistedUser);
        return ResponseData.REP_GET_SUCCESS(info);
    }


    @ApiOperation(value = "设置黑名单", notes = "将用户添加到黑名单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户Id", required = true, dataType = "Integer")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功"),
    })
    @GetMapping("addToBlacklist")
    public boolean addToBlacklist(Integer id) {
        return adminUserService.addToBlacklist(id);
    }


    @ApiOperation(value = "设置白名单", notes = "将用户移出黑名单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户Id", required = true, dataType = "Integer")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功"),
    })
    @GetMapping("removeToBlacklist")
    public boolean removeToBlacklist(Integer id) {
        return adminUserService.removeToBlacklist(id);
    }

}
